package com.myblog.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Describe：static静态资源访问
 * 设置url默认访问的静态资源路径
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
      "classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/"
    };

    /**
     * 添加自定义静态资源映射路径额静态资源存放路径(图片)
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
        registry.addResourceHandler("/static/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
        super.addResourceHandlers(registry);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        // 设置页面注册
        registry.addViewController("/").setViewName("/index.html");
        registry.addViewController("/article").setViewName("/article.html");
        registry.addViewController("/guestBook").setViewName("/guestBook.html");
        registry.addViewController("/about").setViewName("/about.html");
    }

}
